package scau.erps.service.impl;

import org.nutz.dao.Cnd;
import org.nutz.dao.util.cri.SqlExpressionGroup;
import org.nutz.service.IdEntityService;

import scau.erps.app.Erps;
import scau.erps.entity.Research;
import scau.erps.entity.Sand;
import scau.erps.service.ResearchService;

/**
 * 研发服务实现类
 * @author DCJ
 *
 */
public class ResearchServiceImpl extends IdEntityService<Research> implements ResearchService {

	@Override
	public void researchInvest(Research research) {
		int amount = research.getAmount();
		Sand sand = Erps.getSand();
		int cash = sand.getCash();
		sand.setCash(cash-amount);
		this.dao().update(sand);
		this.dao().insert(research);		
	}
	/**
	 * 得到研发投资次数
	 * @param team_Id
	 * @param type
	 * @return
	 */
	public int findResearchs(int team_Id,String type){
		SqlExpressionGroup e1 = null;
		SqlExpressionGroup e2 = null;
		if(team_Id != 0){
			e1 = Cnd.exps("team_Id", "=", team_Id);			
		}
		if(type != null){
			e2 = Cnd.exps("type", "=",type);
		}
		int i = this.query(Cnd.where(e1).and(e2), null).size();
		return i;
	}

}
